﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum GameState
{
    Menu,
    Game,
}

public class ShuaiManager : MonoSingleton<ShuaiManager>
{
    [Header("关卡列表")]
    public List<GameObject> level_list;
    [Header("当前第几关")]
    public int level = 1;
    public GameState game_state = GameState.Menu;

    public GameObject currentLevelGameObject;

    public Camera MainCamera;

    public bool isLoadingLevelComplete = false;

    void Start()
    {
        GoToMenu();
    }
    
    public void GoToMenu()
    {
        ShuaiManager.Instance.level = 0;
        if (currentLevelGameObject != null)
        {
            Destroy(currentLevelGameObject);
        }
        currentLevelGameObject = null;

        SelectLevelPanel.Instance.Open();
        GamePanel.Instance.Close();
        LoadingPanel.Instance.Close();
    }

    //进入某一关
    public void EnterLevel()
    {
        LoadingPanel.Instance.Open();
        CreateLevel();
    }

    public void CreateLevel()
    {
        Debug.Log("加载关卡");

        isLoadingLevelComplete = false;
        
        if (currentLevelGameObject != null)
        {
            Destroy(currentLevelGameObject);
        }
        GameObject levelPrefab = level_list[level - 1] as GameObject;
        currentLevelGameObject = Instantiate(levelPrefab);
        currentLevelGameObject.gameObject.SetActive(false);
        isLoadingLevelComplete = true;

        SelectLevelPanel.Instance.Close();
        
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            Time.timeScale = 0;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            Time.timeScale = 1;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            
        }


        else if (Input.GetKeyDown(KeyCode.Keypad1))
        {
            LoadingPanel.Instance.Open();
        }
        else if (Input.GetKeyDown(KeyCode.Keypad2))
        {
            LoadingPanel.Instance.gameObject.GetComponent<Animator>().SetBool("LoadLevelComplete", true);
        }
        else if (Input.GetKeyDown(KeyCode.Keypad3))
        {
            
        }
        
    }
}
